import UserService from "@src/services/UserService";
import { IReq, IRes, INext } from "@src/routes/common/types";

class UserController {
    getUsers = async (req: IReq, res: IRes, next: INext) => {
        try {
            const userId = req.userId
            const users = await UserService.getUsers(userId as number);
            res.status(users.code).json(users);
        } catch (error) {
            next(error);
        }
    }
    updateUser = async (req: IReq, res: IRes, next: INext) => {
        try {
            const { body } = req;
            const userId = req.userId
            console.log(userId);

            const user = await UserService.updateUser(userId as number, body);
            res.status(user.code).json(user);
        } catch (error) {
            next(error);
        }
    }
    updatePassword = async (req: IReq, res: IRes, next: INext) => {
        try {
            const { body } = req;
            const userId = req.userId
            const user = await UserService.updatePassword(userId as number, body);
            res.status(user.code).json(user);
        } catch (error) {
            next(error);
        }
    }
}

export default new UserController();
